package com.wjh.kt_wechat.config;

import com.wjh.kt_wechat.Utils.ConstantPropertiesUtils;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

/**
 * Wang_Junhong
 * 2022/7/17
 * 文件描述：
 */

@Component
@EnableFeignClients(basePackages = "com.wjh")
@MapperScan("com.wjh.kt_wechat.mapper")
@ComponentScan("com.wjh")
@EnableDiscoveryClient
public class WeChatConfig {

    @Autowired
    private ConstantPropertiesUtils constantPropertiesUtils;

    @Bean
    public WxMpService wxMpService(){
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }
    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        WxMpDefaultConfigImpl wxMpConfigStorage = new WxMpDefaultConfigImpl();
        wxMpConfigStorage.setAppId(constantPropertiesUtils.ACCESS_KEY_ID);
        wxMpConfigStorage.setSecret(constantPropertiesUtils.ACCESS_KEY_SECRET);
        return wxMpConfigStorage;
    }


}
